private voidtextBox1_KeyPress(object sender, KeyPressEventArgs e) { if (char.IsDigit(e.KeyChar)== false && e.KeyChar != '.' && e.KeyChar!='\b') //checking whether pressed key is number, decimal orbackspace. //If false then we will set Handled variable ofKeyPressEventArgs to true. //By doing this system will get a message that character of keypressed //is executed and hence aplpa numeric character will not bedisplayed //except decimal. e.Handled=true; elseif (e.KeyChar == '.') if(textBox1.Text.Contains('.')) e.Handled=true; //checking whether decimal key is pressed or not, if truethen checking //whether decimal is already present or not, as we can haveonly //one decimal point in a text box. }
Liked By
Write Answer
Numeric Textbox
Join MindStick Community
You have need login or register for voting of answers or question.
Uttam Misra
05-Oct-2010http://www.mindstick.com/Articles/6e3c047c-17aa-4ea2-b390-a8b756404f09/